package com.yizhang.health;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;

@Component
public class MyHaHaHealthIndicator extends AbstractHealthIndicator {

    @Autowired
    private MyHaHa myHaHa;


    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        int check = myHaHa.check();
        if (check == 0) {
            builder.up()
                    .withDetail("code", "200")
                    .withDetail("message", "success")
                    .build();
        } else {
            builder.down()
                    .withDetail("code", "500")
                    .withDetail("message", "failure")
                    .build();
        }
    }
}
